<?php
/**
 * Description of ModuleService
 *
 * @author Adam
 */
class ModuleService {
    private static $instance = null;

    public static function getInstance() {
       if (!self::$instance instanceof self) {
         self::$instance = new self;
       }
       return self::$instance;
    }

    public function __destruct() {
    }
    
    public function getAllOrdered($DBprefix,$orderBy) {
        $query = "SELECT * FROM `" . $DBprefix . "modules` ORDER BY `$orderBy` ASC";
        $queryResult = mysql_query($query);
        $modules = array();
        while($module = mysql_fetch_array($queryResult)) {
            $moduleObj = new Module();
            
            $moduleObj->setId( $module["mod_id"] );
            $moduleObj->setName( $module["mod_name"] );
            $moduleObj->setLocation( $module["mod_location"] );
            $moduleObj->setVer( $module["mod_ver"] );
            $moduleObj->setLud( $module["mod_lud"] );
            $moduleObj->setLastUp( date("m.d.Y - H:i:s", $mod_lud) );
            
            $modules[] = $module;
        }
        return $modules;
    }
    
    public function count($DBprefix) {
        $query = "SELECT * FROM `" . $DBprefix . "modules`";
        $queryResult = mysql_query($query);
        $count = mysql_num_rows($queryResult);
        return $count;
    }
}

?>
